﻿package cn.poco.service.impl;

import java.io.InputStream;
import java.util.ArrayList;
import android.util.Log;
import cn.poco.bean.Band;
import cn.poco.bean.ClassBean;
import cn.poco.bean.Restaurant;
import cn.poco.service.IRank;
import cn.poco.util.UrlConnectionUtil;
import cn.poco.util.xmlparse.ClassXmlparse;
import cn.poco.util.xmlparse.RankTypeXmlparse;
import cn.poco.util.xmlparse.RestaurantXmlparse;

public class RankImpl implements IRank {

	private final static  String TAG = "RankImpl";
	@Override
	public ArrayList<Band> GetRanksByCitycode(String citycode,String type) throws Exception {
		String url = null;
		InputStream insteam = null;
		if(citycode!=null && !citycode.equals("")){
			url = RANK_TYPE_PATH.replace("#a", citycode);
			if(type!=null && !type.equals("")){
				url = url +"&t=1";
			}
			insteam = UrlConnectionUtil.getRequest(url);
		}
		Log.i(TAG, url);
		return RankTypeXmlparse.getXml(insteam);
	}

	@Override
	public ArrayList<Restaurant> GetResByRankid(String rankid)
			throws Exception {
		String url = null;
		InputStream insteam = null;
		if(rankid!=null && !rankid.equals("")){
			url = RANK_RES_PaTH.replace("#a", rankid);
			insteam = UrlConnectionUtil.getRequest(url);
		}
		Log.i("RankImpl", url);
		return RestaurantXmlparse.getXml(insteam);
	}

	@Override
	public ArrayList<Restaurant> GetTopRes(String citycode, int s, int l)
			throws Exception {
		String url = null;
		InputStream insteam = null;
		if(!citycode.equals("") && s>=0 && l>0){
			url = RANK_TOP_PATH.replace("#a", citycode)
					.replace("#b", String.valueOf(s))
					.replace("#c", String.valueOf(l));
			insteam = UrlConnectionUtil.getRequest(url);
		}
		Log.i(TAG, url);
		return RestaurantXmlparse.getXml(insteam);
	}

	@Override
	public ArrayList<ClassBean> getResClass(String citycode) throws Exception {
		String url = null;
		InputStream insteam = null;
		if(!citycode.equals("") && !citycode.equals("")){
			url = RANK_CLASS_PATH.replace("#a", citycode);
			insteam = UrlConnectionUtil.getRequest(url);
		}
		Log.i(TAG, url);
		return ClassXmlparse.getXml(insteam);
	}

	@Override
	public ArrayList<Restaurant> getResByClassId(String citycode, String classId,int s,int l)
			throws Exception {
		String url = null;
		InputStream insteam = null;
		if(citycode!=null && classId!=null){
			url = RANK_RES_CLASSID_PATH.replace("#a", citycode)
						.replace("#b", classId)
						.replace("#c", String.valueOf(s))
						.replace("#d", String.valueOf(l));
			
			insteam =  UrlConnectionUtil.getRequest(url);
		}
		Log.i(TAG, url);
		return  RestaurantXmlparse.getXml(insteam);
	}

}
